package com.example.leave.component.valid.impl;

import com.example.leave.component.valid.PropertiesMostInLeaveForm;
import com.example.leave.entity.LeaveForm;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.lang.reflect.Field;

public class PropertiesMostInLeaveFormImpl implements ConstraintValidator<PropertiesMostInLeaveForm, String> {

    @Override
    public void initialize(PropertiesMostInLeaveForm constraintAnnotation) {

    }

    @Override
    public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
        LeaveForm leaveForm = new LeaveForm();
        if (null == s) {
            return false;
        }
        Field[] fields = leaveForm.getClass().getDeclaredFields();
        for (Field f : fields) {
            if (f.getName().equals(s)) {
                return true;
            }
        }
        return false;
    }
}
